import Mock from "mockjs";

// 逻辑： 先输入手机号码  再发送验证码
import { ListApply } from "./loginMock";
import { List } from "./loginMock";
export default {
  applyData: (config) => {
    let { phone } = JSON.parse(config.body);

    let code = "";
    if (!phone) {
      // console.log('验证码获取失败')
      return;
    } else if (!/^1[345678]\d{9}$/.test(phone)) {
      // console.log('验证码获取失败')
      return;
    } else {
      code = Mock.mock('@string("number", 6)');
      // console.log('验证码获取成功')
    }
    return {
      code: 200,
      msg: "请求成功",
      data: code,
    };
  },

  applyCheckData: (config) => {
    let { phone, code, username } = JSON.parse(config.body);
    console.log("填写信息为：" + phone, username + ",密码默认为123456");
    // let token = `${username}+'-'+${phone}`;
    // console.log(ListApply);
    ListApply.push({ username: username, password: 123456 });
    // console.log(ListApply);
    // console.log("ListApply.phone", ListApply.phone);
    // console.log("List.phone", List.phone);
    // console.log("List", List);
    // console.log("phone", phone);
    let newLi = List.find((item) => phone == item.phone);
    if (newLi) {
      return {
        code: 101,
        msg: "请求失败，该手机号已存在",
        data: null,
      };
    } else {
      return {
        code: 200,
        msg: "请求成功",
        data: null,
      };
    }
  },
};
